﻿Imports System.IO
Imports DBase.scafolding.Config
Imports System.Net

Partial Class Varie_Default
    Inherits MyUI.PageBaseSite

    'Dim db As mDB_Geo = mDB_Geo.GetDB
    Public Val As String

    Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init

        Val = UI.Page.GetValue("t")

        Dim conf As New Dictionary(Of String, ConfigTable)

        conf.Add("user", Users)
        conf.Add("account", Account)
        conf.Add("account_link", Account_link)

        CustomControlGrid.Config = conf(Val)


        'CustomControlEdit.Config = CustomControlGrid.Config
        'CustomControlEdit.Visible = False


        'Response.Write((New UI.Validator.EmailValidator("lollo@lollo.com")).ValidatorCheck.GetByType(UI.Validator.ValidatorResultType.Error).Count())



    End Sub

    Protected Sub CustomControlGrid_DeleteInLine(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventDeleteInLine

    End Sub

    Protected Sub CustomControlGrid_EventInsertInLine(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventInsertInLine

    End Sub

    Protected Sub CustomControlGrid_EventEditInLine(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventEditInLine

    End Sub

    Protected Sub CustomControlGrid_Elimina(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventDeleteOutLine

        'Me.CustomControlEdit.Status = TypeEdit.StatusType.Delete
        'Me.CustomControlEdit.Visible = True
        'Me.CustomControlEdit.PK = id
        'Me.CustomControlEdit.Bind()

    End Sub

    Protected Sub CustomControlGrid_Inserimento() Handles CustomControlGrid.EventInsertOutLine

        'Me.CustomControlEdit.Status = TypeEdit.StatusType.Insert
        'Me.CustomControlEdit.Visible = True
        'Me.CustomControlEdit.Bind()

    End Sub

    Protected Sub CustomControlGrid_Modifica(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventEditOutLine

        'Me.CustomControlEdit.Status = TypeEdit.StatusType.Update
        'Me.CustomControlEdit.Visible = True
        'Me.CustomControlEdit.PK = id
        'Me.CustomControlEdit.Bind()

    End Sub

    Protected Sub CustomControlGrid_Seleziona(id As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlGrid.EventSelectInLine

    End Sub

    'Protected Sub CustomControlEdit_DataCanc() Handles CustomControlEdit.DataCanc

    '    Me.CustomControlEdit.Visible = False
    '    Me.CustomControlGrid.Bind()
    '    Me.CustomControlEdit.Bind()

    'End Sub

    'Protected Sub CustomControlEdit_DataDelete(list As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlEdit.DataDelete

    '    Me.CustomControlGrid.Bind()

    'End Sub

    'Protected Sub CustomControlEdit_DataEdit() Handles CustomControlEdit.DataEdit

    '    Me.CustomControlEdit.Visible = False
    '    Me.CustomControlGrid.Bind()

    'End Sub

    'Protected Sub CustomControlEdit_DataInsert(list As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlEdit.DataInsert

    '    Me.CustomControlGrid.Bind()

    'End Sub

    'Protected Sub CustomControlEdit_DataUpdate(list As System.Collections.Generic.Dictionary(Of String, Object)) Handles CustomControlEdit.DataUpdate

    '    Me.CustomControlGrid.Bind()

    'End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub

    Protected Function Users() As ConfigTable

        Return New ConfigTable With {
            .Table = "user", .SqlView = "select * from user", .DB = mDB.GetDB, .GridPageSize = 20,
            .Fields = New List(Of Field) From {
                New Field With {.Name = "id", .LabelName = "id", .FieldType = GetType(Integer), .Primary = True, .[ReadOnly] = True},
                New Field With {.Name = "email", .LabelName = "e-mail", .FieldType = GetType(String)},
                New Field With {.Name = "password", .LabelName = "password", .FieldType = GetType(String)},
                New Field With {.Name = "name", .LabelName = "name", .FieldType = GetType(String)},
                New Field With {.Name = "surname", .LabelName = "sur name", .FieldType = GetType(String)},
                New Field With {
                    .Name = "plan_id", .LabelName = "Plain", .InputType = ConfigTable.InputType.DropDownList, .NotNull = True,
                    .JoinFieldLink = "id", .JoinFieldView = "description",
                    .ConfigTable = New ConfigTable With {.Table = "plan", .SqlView = "select * from plan", .DB = mDB.GetDB}
                },
                New Field With {
                    .Name = "id", .LabelName = "accounts", .InputType = ConfigTable.InputType.SearchView,
                    .JoinFieldLink = "user_id",
                    .ConfigTable = New ConfigTable With {
                        .Table = "user_account", .SqlView = "select * from user_account", .DB = mDB.GetDB,
                        .Fields = New List(Of Field) From {
                            New Field With {.Name = "user_id", .LabelName = "id", .FieldType = GetType(Integer), .Primary = True, .[ReadOnly] = True, .ShowInLine = False},
                            New Field With {
                                .Name = "account_id", .LabelName = "Account collegato", .Primary = True, .InputType = ConfigTable.InputType.SearchBox,
                                .JoinFieldLink = "id", .JoinFieldView = "fullname",
                                .ConfigTable = Account()
                            },
                            New Field With {.Name = "account_id", .LabelName = "ACCOUNT", .[ReadOnly] = True, .Link = "?t=account&filter_table=account&filter_field=id&filter_value={0}"}
                        }
                    }
                }
            }
        }



        '                New Field With {.Name = "last_view_alert_date", .LabelName = "last_view_alert_date", .InputType = ConfigTable.InputType.Date},



    End Function

    Protected Function Account() As ConfigTable

        Return New ConfigTable With {
            .Table = "account", .SqlView = "select * from account", .DB = mDB.GetDB, .GridPageSize = 100,
            .Fields = New List(Of Field) From {
                New Field With {.Name = "id", .LabelName = "id", .FieldType = GetType(Integer), .Primary = True, .[ReadOnly] = True},
                New Field With {.Name = "fullname", .LabelName = "fullname", .FieldType = GetType(String)},
                New Field With {.Name = "username", .LabelName = "username", .FieldType = GetType(String)},
                New Field With {.Name = "location", .LabelName = "location", .FieldType = GetType(String)},
                New Field With {.Name = "description", .LabelName = "description", .EditOnly = True, .FieldType = GetType(String)},
                New Field With {.Name = "joined_date", .LabelName = "joined_date", .ReadOnly = True},
                New Field With {.Name = "id", .LabelName = "UPDATE", .[ReadOnly] = True, .Link = "?t=account_add_info&filter_table=account_add_info&filter_field=account_id&filter_value={0}"},
                New Field With {.Name = "id", .LabelName = "ADD INFO", .[ReadOnly] = True, .Link = "?t=account_update&filter_table=account_update&filter_field=account_id&filter_value={0}"},
                New Field With {.Name = "id", .LabelName = "LINK", .[ReadOnly] = True, .Link = "?t=account_link&filter_table=account_link&filter_field=account_id&filter_value={0}"}
            }
        }

        '                New Field With {.Name = "last_view_alert_date", .LabelName = "last_view_alert_date", .InputType = ConfigTable.InputType.Date},



    End Function
    Protected Function Account_link() As ConfigTable

        Return New ConfigTable With {
            .Table = "account_link", .SqlView = "select account.*,account_link.*,acc_link.username as link_username from account_link inner join account on account.id = account_link.account_id inner join account as acc_link on acc_link.id = account_link.account_link_id", .DB = mDB.GetDB,
            .Fields = New List(Of Field) From {
                New Field With {.Name = "account_id", .LabelName = "account id", .FieldType = GetType(Integer), .[ReadOnly] = True},
                New Field With {
                    .Name = "account_id", .LabelName = "Account", .Primary = True, .InputType = ConfigTable.InputType.SearchBox,
                    .JoinFieldLink = "id", .JoinFieldView = "fullname",
                    .ConfigTable = Account()
                },
                New Field With {.Name = "link_type_id", .LabelName = "link_type_id", .FieldType = GetType(Integer), .Primary = True},
                New Field With {
                    .Name = "account_link_id", .LabelName = "Account collegato", .Primary = True, .InputType = ConfigTable.InputType.SearchBox,
                    .JoinFieldLink = "id", .JoinFieldView = "fullname",
                    .ConfigTable = Account()
                }
            }
        }

        '                New Field With {.Name = "last_view_alert_date", .LabelName = "last_view_alert_date", .InputType = ConfigTable.InputType.Date},



    End Function



End Class


